package com.youngjun.user.controller.admin;

import com.youngjun.common.mybatis.web.BaseController;
import com.youngjun.common.mybatis.web.Response;
import com.youngjun.user.api.admin.IRoleRestApi;
import com.youngjun.user.pojo.dto.RoleDTO;
import com.youngjun.user.pojo.dto.query.RoleQueryDTO;
import com.youngjun.user.pojo.vo.RoleVO;
import com.youngjun.user.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController implements IRoleRestApi,BaseController {

    @Autowired
    RoleService roleService;

    @Override
    public Response<List<RoleVO>> queryListByCurrentRole() {
        List<RoleVO> data = roleService.queryListByCurrentRole();
        return new Response<>(data);
    }

    @Override
    public Response<RoleVO> createByCurrentRole(RoleDTO dto) {
        RoleVO data = roleService.createByCurrentRole(dto);
        return new Response<>(data);
    }

    @Override
    public Response<RoleVO> modifyByCurrentRole(RoleDTO dto) {
        RoleVO data = roleService.modifyByCurrentRole(dto);
        return new Response<>(data);
    }

    @Override
    public Response<Void> deleteByCurrentRole(Long id) {
        roleService.deleteByCurrentRole(id);
        return new Response<>();
    }

    @Override
    public Response<List<RoleVO>> queryListByCurrentOrganization(@RequestBody RoleQueryDTO dto) {
        List<RoleVO> data = roleService.queryListByCurrentOrganization(dto);
        return new Response<>(data);
    }

    @Override
    public Response<List<RoleVO>> queryList(@RequestBody RoleQueryDTO dto) {
        List<RoleVO> data = roleService.queryList(dto);
        return new Response<>(data);
    }

    @Override
    public Response<RoleVO> create(@RequestBody @Valid RoleDTO dto){
        RoleVO data = roleService.create(dto);
        return new Response<>(data);
    }

    @Override
    public Response<RoleVO> modify(@RequestBody @Valid RoleDTO dto){
        RoleVO data = roleService.modify(dto);
        return new Response<>(data);
    }

    @Override
    public Response<Void> delete(@RequestParam("id") Long id){
        roleService.delete(id);
        return new Response<>();
    }

}